﻿// <copyright file="DefaultXmlToCLRTypeMapping.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-04-17</date>
// <summary>Maps XML type to CLR type using default MS mapping.</summary>
// <revision>$Id$</revision>

using System;
using System.Xml;

namespace OpenWPFChart.Helpers.XmlItemDataReader
{
	/// <summary>
	/// Maps XML type to CLR type using default MS mapping.
	/// </summary>
	public static class DefaultXmlToCLRTypeMapping
	{
		/// <summary>
		/// Converts the XML type to the CLR type.
		/// </summary>
		/// <param name="xsdType">XML type name.</param>
		/// <returns></returns>
		public static Type FromXmlType(string xsdType)
		{
			switch (xsdType)
			{
				// xs types (http://www.w3.org/2001/XMLSchema)
				case "anyURI":
					return typeof(Uri);
				case "base64Binary":
					return typeof(Byte[]);
				case "boolean":
					return typeof(Boolean);
				case "byte":
					return typeof(SByte);
				case "date":
					return typeof(DateTime);
				case "dateTime":
					return typeof(DateTime);
				case "decimal":
					return typeof(Decimal);
				case "double":
					return typeof(Double);
				case "duration":
					return typeof(TimeSpan);
				case "ENTITIES":
					return typeof(String[]);
				case "ENTITY":
					return typeof(String);
				case "float":
					return typeof(Single);
				case "gDay":
					return typeof(DateTime);
				case "gMonthDay":
					return typeof(DateTime);
				case "gYear":
					return typeof(DateTime);
				case "gYearMonth":
					return typeof(DateTime);
				case "hexBinary":
					return typeof(Byte[]);
				case "ID":
					return typeof(String);
				case "IDREF":
					return typeof(String);
				case "IDREFS":
					return typeof(String[]);
				case "int":
					return typeof(Int32);
				case "integer":
					return typeof(Decimal);
				case "language":
					return typeof(String);
				case "long":
					return typeof(Int64);
				case "gMonth":
					return typeof(DateTime);
				case "Name":
					return typeof(String);
				case "NCName":
					return typeof(String);
				case "negativeInteger":
					return typeof(Decimal);
				case "NMTOKEN":
					return typeof(String);
				case "NMTOKENS":
					return typeof(String[]);
				case "nonNegativeInteger":
					return typeof(Decimal);
				case "nonPositiveInteger":
					return typeof(Decimal);
				case "normalizedString":
					return typeof(String);
				case "NOTATION":
					return typeof(XmlQualifiedName);
				case "positiveInteger":
					return typeof(Decimal);
				case "QName":
					return typeof(XmlQualifiedName);
				case "short":
					return typeof(Int16);
				case "string":
					return typeof(String);
				case "time":
					return typeof(DateTime);
				case "token":
					return typeof(String);
				case "unsignedByte":
					return typeof(Byte);
				case "unsignedInt":
					return typeof(UInt32);
				case "unsignedLong":
					return typeof(UInt64);
				case "unsignedShort":
					return typeof(UInt16);
				case "anySimpleType":
					return typeof(String);
				// xdt types (http://www.w3.org/2003/05/xpath-datatypes)
				case "dayTimeDuration":
					return typeof(TimeSpan);
				case "yearMonthDuration":
					return typeof(TimeSpan);
				case "untypedAtomic":
					return typeof(String);
				case "anyAtomicType":
					return typeof(Object);
			}
			return null;
//Document node - XPathNavigator
//Element node - XPathNavigator
//Attribute node - XPathNavigator
//Namespace node - XPathNavigator
//Text node - XPathNavigator
//Comment node - XPathNavigator
//Processing instruction node - XPathNavigator
		}
	}
}
